package com.ptu.controller.admin;

import com.ptu.server.ChartService;
import com.ptu.util.Result;
import com.ptu.vo.CategorySalesVO;
import com.ptu.vo.SalesTrendVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/chart")
public class ChartController {
    @Autowired
    private ChartService chartService;

    //  销售趋势
    @GetMapping("/salesTrend")
    public Result<List<SalesTrendVO>> getSalesTrend(@RequestParam String type) {
        if (!"week".equalsIgnoreCase(type) && !"month".equalsIgnoreCase(type)) {
            return Result.error("参数错误，请传入week或month");
        }
        List<SalesTrendVO> data = chartService.getSalesTrend(type);
        return Result.success(data);
    }

    //  商品分类销售
    @GetMapping("/categorySales")
    public Result<List<CategorySalesVO>> getCategorySales() {
        List<CategorySalesVO> data = chartService.getCategorySales();
        return Result.success(data);
    }
}